package com.reserv.util;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class TimestampUtil {
	public Timestamp toTimestamp(String str) {
		SimpleDateFormat sdf = null;
		Date date = null;
		try {
			if(!(str == null || str.length() == 0)) {
				sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				date = sdf.parse(str + " 00:00:00");
				return new Timestamp(date.getTime());
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	public String dropSec(Timestamp ts) throws ParseException {
		Calendar cal = Calendar.getInstance();
		cal.setTimeInMillis(ts.getTime());
		return cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.DAY_OF_MONTH);
	}
	public Timestamp getToday() {
		Date date = new Date();
		return new Timestamp(date.getTime());
	}

}
